<%-- 
    Document   : ProsesLogin
    Created on : Dec 2, 2012, 8:42:08 PM
    Author     : Ronny
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="bean.ProsesBean"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <form  method="post" action="">
            <%
                String userName = request.getParameter("userName");
                String pass = request.getParameter("password");
                String status = request.getParameter("status");
                System.out.println(userName);
                System.out.println(status);

                if (userName == null) {
                    userName = "";
                }
                if (pass == null) {
                    pass = "";
                }
                
                ProsesBean beanproses = new ProsesBean();
                if (status.matches("guru")) {
                    ResultSet rest = beanproses.loginGuru(userName, pass);
                    int jml = 0;
                    while (rest.next()) {
                        jml++;
                    }
                    if (jml == 1) {
                        session.setAttribute("user", userName);
                        session.setAttribute("password", pass);
                        response.sendRedirect("FormUtamaGuru.jsp");
                    } else {
                        response.sendRedirect("FormLogin.jsp?error=y");
                    }
                } else if (status.matches("wali")) {
                    ResultSet rest = beanproses.loginWali(userName, pass);
                    int jml = 0;
                    while (rest.next()) {
                        jml++;
                    }
                    if (jml == 1) {
                        session.setAttribute("user", userName);
                        session.setAttribute("password", pass);
                        response.sendRedirect("FormUtamaWaliMurid.jsp");
                    } else {
                        response.sendRedirect("FormLogin.jsp?error=y");
                    }
                } else if (status.matches("tu")) {
                    ResultSet rest = beanproses.loginTu(userName, pass);
                    int jml = 0;
                    while (rest.next()) {
                        jml++;
                    }
                    if (jml == 1) {
                        session.setAttribute("user", userName);
                        session.setAttribute("password", pass);
                        response.sendRedirect("FormInputDataSiswa.jsp");
                    } else {
                        response.sendRedirect("FormLogin.jsp?error=y");
                    }
                }
            %>
        </form>
    </body>
</html>
